/*
biopp.cpp: Molecular Biology ++ Implementation file.
    Copyright (C) 2009, 2010, 2011 Daniel Gutson and Martin Gioiosa, FuDePAN

    This file is part of Biopp.

    Biopp is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Biopp is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Biopp.  If not, see <http://www.gnu.org/licenses/>.

    NOTE: This file is in prototype stage, and is under active development.
*/

#include <iostream>
#include "biopp/biopp.h"
#include "biopp/bio_molecular/biopp_debug.h"

using namespace std;

namespace biopp
{

void NucSequence::translate(AminoSequence& aminoseq) const
{
    const size_t ntriplets(triplets_length());
    aminoseq.clear();

    for (size_t t = 0; t < ntriplets; t++)
        aminoseq.push_back(get_triplet(t).translate());
}

PseudoNucSequence& PseudoNucSequence::operator=(const NucSequence& nuc)
{
    const size_t size = nuc.length();

    clear();
    if (size != 0)
    {
        seq.reserve(size);
        for (size_t i = 0; i < size; i++)
        {
            addNucleotide(PseudoNucleotide(nuc[i]));
        }
    }
    return *this;
}

void PseudoNucSequence::set_triplet(size_t i, const Triplet& t) throw(OutOfRange)
{
    if (i >= triplets_length())
        throw OutOfRange();

    const size_t tripletPosition = calcTripletPosition(i);

    seq[tripletPosition] = t[0];
    seq[tripletPosition + 1] = t[1];
    seq[tripletPosition + 2] = t[2];
}

bool PseudoNucSequence::isPureSequence() const
{
    bool isPure = true;

    std::vector<PseudoNucleotide>::const_iterator it = seq.begin();

    while (it != seq.end() && isPure)
    {
        isPure = isPureNucleotide(*it);
        ++it;
    }

    return isPure;
}
}
